//
//  HWNavigationController.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/29.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit

class HWNavigationController: UINavigationController, UIGestureRecognizerDelegate {
    
    override var shouldAutorotate : Bool {
        return false
       }
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
        return .portrait
    }
    override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
        return .portrait
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        UINavigationBar.appearance().isTranslucent = false
        
        
        let textAttributes = [NSAttributedString.Key.font:UIFont.boldSystemFont(ofSize: 18),NSAttributedString.Key.foregroundColor:UIColor.colorWithHexString(hexString: "#333333")]
        UINavigationBar.appearance().titleTextAttributes = textAttributes
        
        UINavigationBar.appearance().tintColor = UIColor.colorWithHexString(hexString: "#333333")
//        UINavigationBar.appearance().barTintColor = UIColor.white
//        UINavigationBar.appearance().backIndicatorImage = UIImage()
        
        UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "navBack")
//        UINavigationBar.appearance().backIndicatorImage = UIImage(named: "navBack")
        UINavigationBar.appearance().shadowImage = UIImage()
        self.interactivePopGestureRecognizer?.delegate = self
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
//        if (self.children.count > 0) {
//            // 恢复滑动返回功能 -> 分析:把系统的返回按钮覆盖 -> 1.手势失效(1.手势被清空 2.可能手势代理做了一些事情,导致手势失效)
//            viewController.hidesBottomBarWhenPushed = true;
//            viewController.navigationItem.leftBarButtonItem = HWNavigationController.backItemWithimage(image: UIImage(named: "fanhuijianicotubiao") ?? UIImage(), highImage:  UIImage(named: "fanhuijianicotubiao") ?? UIImage(), target: self, action: #selector(self.back), title: " ")
//
//
//
//        }
        
        super.pushViewController(viewController, animated: true)
    }
    
//    class  func backItemWithimage(image:UIImage , highImage : UIImage  , target : UIViewController ,action :(Selector) ,title :String ) -> UIBarButtonItem {
//
//        let backButton = UIButton(type: .custom)
//      //  backButton.backgroundColor =[UIColor redColor];
//        backButton.setTitle(title, for: UIControl.State.normal)
//        backButton.setImage(image, for: .normal)
//        backButton.setImage(highImage, for: .highlighted)
//        backButton.sizeToFit()
//        backButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: -5, bottom: 0, right: 0);
//
//        backButton.sizeToFit()
//        backButton.addTarget(target, action: action, for: UIControl.Event.touchUpInside)
//
//        return UIBarButtonItem(customView: backButton)
//
//
////        [backButton setImage:image forState:UIControlStateNormal];
////        [backButton setImage:highImage forState:UIControlStateHighlighted];
////        [backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
////        [backButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
////        [backButton sizeToFit];
////        backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
////        [backButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
//
//    }
    
//    @objc func  back() {
//        self.popViewController(animated: false)
//    }

}
